import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//静态加载 初始化看到的页面和框架
import Login from '@/views/login'
import Layout from '@/layout/layout.vue'

//隐藏原地跳转错误
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

//配置路由地址 和 页面组件的一一对应关系
const routes = [
  /* 首页重定向 */
  {
    path: '/',
    redirect: '/home',
  },
  /* 登录 */
  {
    path: '/login',
    component: Login,
  },
  /* 首页 */
  {
    path: '/home',
    meta:{path:'/',title:'后台首页'},
    component: Layout, //框架
    children: [
      {
        path: '',
        component: () => import('@/views/home'),
      },
    ],
  },
  /* 订单管理 */
  {
    meta:{path:'/order',title:'订单管理'},
    path: '/order',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/order'),
      },
    ],
  },
  // 店铺管理
    {
      meta:{path:'/shop',title:'店铺管理'},
    path: '/shop',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/shop'),
      },
    ],
  },
  /* 商品管理 */
  {
    meta:{path:'/goods',title:'商品管理'},
    path: '/goods',
    component: Layout,
    redirect: '/goods/goods-list',
    children: [
      {
        meta:{path:'/goods/goods-list',title:'商品列表'},
        path: 'goods-list', //不写斜杠相当于/goods/goods-list
        component: () => import('@/views/goods/goods-list'),
      },
      {
        meta:{path:'/goods/goods-add',title:'添加商品'},
        path: '/goods/goods-add',
        component: () => import('@/views/goods/goods-add'),
      },
      {
        meta:{path:'/goods/goods-kinds',title:'商品分类'},
        path: '/goods/goods-kinds',
        component: () => import('@/views/goods/goods-kinds'),
      },
    ],
  },
  /* 账号管理 */
  {
    meta:{path:'/account',title:'账号管理'},
    path: '/account',
    component: Layout,
    redirect: '/account/account-list',
    children: [
      {
        meta:{path:'/account/account-list',title:'账号列表'},
        path: 'account-list',
        component: () => import('@/views/account/account-list'),
      },
      {
        meta:{path:'/account/account-add',title:'添加账号'},
        path: '/account/account-add',
        component: () => import('@/views/account/account-add'),
      },
      {
        meta:{path:'/account/password',title:'修改密码'},
        path: '/account/password',
        component: () => import('@/views/account/account-password'),
      },
      {
        meta:{path:'/account/account-person',title:'个人中心'},
        path: '/account/account-person',
        component: () => import('@/views/account/account-person'),
      },
    ],
  },
  /* 销售统计 */
  {
    meta:{path:'/total',title:'销售统计'},
    path: '/total',
    component: Layout,
    redirect: '/total/total-goods',
    children: [
      {
        meta:{path:'/total/total-goods',title:'商品统计'},
        path: '/total/total-goods',
        component: () => import('@/views/total/total-goods'),
      },
      {
        meta:{path:'/total/total-order',title:'订单统计'},
        path: '/total/total-order',
        component: () => import('@/views/total/total-order'),
      },
    ],
  },
]

const router = new VueRouter({
  routes,
})

export default router
